//记录查询出的所有用户信息
var adminWxUserobj=new Object();

Ext.onReady(function(){
	wxUseriswriteidb= Ext.get('wxUseriswriteid').getValue()==1?true:false;
	
	var adminWxUsernkey=new Ext.form.ComboBox({
		fieldLabel: '选择用户',
		editable:false,
        store: new Ext.data.JsonStore({
        	autoLoad:true,
            url:'selectAdminUsers.do',
            fields:['nUserId','sName']
        }),
        mode:'local',
	    valueField:'nUserId',
	    displayField:'sName',
        emptyText:'请选择',
        triggerAction:'all',
        selectOnFocus:true,
        listeners:{
        	select:function(combo, record,index)  {
        		adminSelectWxUser();
        	}
	    }
	});

function adminSelectWxUser(){
	Ext.Ajax.request({
			url:'adminSelectWxUser.do',
			method:'GET',
			params:{
				userid:adminWxUsernkey.getValue()
			},
			success:function(response){
				adminWxUserobj=Ext.decode(response.responseText);
				wxUserName.setValue(adminWxUserobj.sname);
				wxUsersAccont.setValue(adminWxUserobj.swxAccount);
				wxUserDeveloperURL.setValue(adminWxUserobj.sdeveloperURL);
				wxUserToken.setValue(adminWxUserobj.stoken);
				wxUserAppID.setValue(adminWxUserobj.sappID);
				wxUserAppSecret.setValue(adminWxUserobj.sappSecret);
				wxUserRemark.setValue(adminWxUserobj.sremark);
				wxUserType.setValue(adminWxUserobj.ntype>0?adminWxUserobj.ntype:1);
			},
			failure:function(){
				Ext.Msg.alert('ERROR','错误');
			}
		});
}
	
	var adminWxUserSearch=new Ext.Panel({
		height:50,
		region:'north',
		layout:'column',
		frame: true,
		border:false,
		bodyBorder:false,
		items:[
			{columnWidth:.38,layout:'form',labelAlign:'right',items:[adminWxUsernkey]}
		]
	});

	var wxUserName=new Ext.form.TextField({
		fieldLabel:'用户姓名',
		width:200
	});
	var wxUsersAccont=new Ext.form.TextField({
		fieldLabel:'微信号',
		width:200
	});
	var wxUserDeveloperURL=new Ext.form.TextField({
		fieldLabel:'开发者URL',
		width:500
	});
	var wxUserToken=new Ext.form.TextField({
		fieldLabel:'Token',
		width:200
	});
	var wxUserAppID=new Ext.form.TextField({
		fieldLabel:'AppID',
		width:200
	});
	var wxUserAppSecret=new Ext.form.TextField({
		fieldLabel:'AppSecret',
		width:200
	});
	var wxUserRemark=new Ext.form.TextArea({
		fieldLabel:'备注',
		width:500,
		height:100
	});
	
	var wxUserType=new Ext.form.ComboBox({
		fieldLabel:'用户类型',
		width:100,
		labelAlign:'right',
		editable:false,
        store: new Ext.data.ArrayStore({
            fields: ['value', 'text'],
            data:[
			        [1, '订阅号'],
			        [2, '服务号']
		        ]
        }),
	    valueField:'value',
	    displayField:'text',
        mode:'local',
        typeAhead: true,
        triggerAction: 'all',
        value:1,
        selectOnFocus:true
	});
	
	var wxUserupbtn=new Ext.Button({
		text:'修  改',
		width:80,
		hidden:wxUseriswriteidb,
		style:'margin-left:100px;margin-top:20px',
		handler:function(){
			
			Ext.Ajax.request({
				url:'adminUpWxUser.do',
				method:'POST',
				params : {
				   'nUserId':adminWxUserobj.nuserId,
				   'nWxUserId':adminWxUserobj.nwxUserId,
				   'ntype':	wxUserType.getValue(),
				   'sAppID':	wxUserAppID.getValue(),
				   'sAppSecret':	wxUserAppSecret.getValue(),
				   'sDeveloperURL':	wxUserDeveloperURL.getValue(),
				   'sName':	wxUserName.getValue(),
				   'sRemark':	wxUserRemark.getValue(),
				   'sToken':	wxUserToken.getValue(),
                   'sWxAccount' :	wxUsersAccont.getValue()
                }, 
  				success: function (response) {

  					if(response.responseText=='1'){
  						Ext.Msg.alert("信息","信息修改成功！"); 
  					}else{
  						Ext.Msg.alert('ERROR','信息修改失败! ');
  					}
              	}, 
  				failure: function (response) {
                    Ext.Msg.alert("Error","错误"); 
            	}
			});
			
		}
	});
	
	var wxUserformPanel=new Ext.FormPanel({
		region:'center',
		frame:true,
		labelAlign:'right',
		items:[wxUserName,wxUsersAccont,wxUserAppID,wxUserAppSecret,wxUserToken,
			wxUserDeveloperURL,wxUserType,wxUserRemark,wxUserupbtn
		]
	});
	
	var wxUserMainPanel =new Ext.Viewport({
		layout:'border',
		renderTo:'wxUserDIV',
		id:'wxUserMainPanel',
		items:[wxUserformPanel,adminWxUserSearch],
		listeners: {
	        'resize': function(viewport,adjWidth,adjHeight,rawWidth,rawHeight)  {
	          	Ext.getCmp("wxUserMainPanel").setHeight((document.body.clientHeight - 290) * 0.67);  
			}
    	}
	});
	
});